import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:go_router/go_router.dart';
import 'package:leader_doctor_flutter/common/utils/string_utils.dart';
import 'package:leader_doctor_flutter/common/widget/comm_widget.dart';
import 'package:leader_doctor_flutter/styles/colors.dart';

typedef void OnConfirmCallback(BuildContext context, VoidCallback closeDialog);

class BottomGeneralDialog {
  ///@description: 页面底部通用弹框
  /// title 弹框顶部标题
  /// desc 弹框文案描述 - 中间部分 - 优先级比 desc 低
  /// descContainer 弹框中间部分 - 优先级比 desc 高
  /// descColor desc文案颜色 - 只针对desc
  /// descFontSize desc文案字体大小 - 只针对desc 默认为16.sp
  /// onCancel 取消事件
  /// onConfirm 确认事件
  /// cancelBoxDecoration 取消按钮的BoxDecoration样式 有默认样式
  /// confirmBoxDecoration 确认按钮的BoxDecoration样式 有默认样式
  /// cancelButtonColor 取消按钮背景色 - 默认为 colorDDEBFF
  /// confirmBoxDecoration 确认按钮背景色 - 默认为 color0065ff
  /// confirmTextColor 取消按钮文案颜色 - 默认为 white
  /// cancelTextColor 确定按钮文案颜色 - 默认为 color0065ff
  /// cancelText 取消按钮标题 - 默认为 取消
  /// confirmText 确认按钮标题 - 默认为 确定
  /// buttonFontSize 按钮标题字体大小 - 默认为 14.sp
  static showBottomGeneralDialog(
    BuildContext context, {
    String? title = "温馨提示",
    required String desc,
    // Container? descContainer,
    Widget? Function(BuildContext context)? descContainer,
    Color? descColor, // = ColorRes.color333333,
    double? descFontSize, // = 16,
    VoidCallback? onCancel,
    VoidCallback? onConfirm,
    BoxDecoration? cancelBoxDecoration,
    BoxDecoration? confirmBoxDecoration,
    Color? cancelButtonColor, // = ColorRes.colorDDEBFF,
    Color? confirmButtonColor, // = ColorRes.color0065ff,
    Color? confirmTextColor, // = Colors.white,
    Color? cancelTextColor, // = ColorRes.color0065ff,
    String? cancelText, // = '取消',
    String? confirmText, // = '确定',
    double? buttonFontSize, // = 14,
  }) {
    buildBottomSheetDialog(
      context,
      title: title,
      desc: desc,
      descContainer: descContainer,
      descColor: descColor,
      descFontSize: descFontSize,
      onCancel: onCancel,
      onConfirm: onConfirm,
      cancelBoxDecoration: cancelBoxDecoration,
      confirmBoxDecoration: confirmBoxDecoration,
      cancelButtonColor: cancelButtonColor,
      confirmButtonColor: confirmButtonColor,
      confirmTextColor: confirmTextColor,
      cancelTextColor: cancelTextColor,
      cancelText: cancelText,
      confirmText: confirmText,
      buttonFontSize: buttonFontSize,
    );
  }

  static buildBottomSheetDialog(
    BuildContext context, {
    String? title,
    required String desc,
    Widget? Function(BuildContext context)? descContainer,
    Color? descColor = ColorRes.color333333,
    double? descFontSize = 16,
    VoidCallback? onCancel,
    VoidCallback? onConfirm,
    BoxDecoration? cancelBoxDecoration,
    BoxDecoration? confirmBoxDecoration,
    Color? cancelButtonColor = ColorRes.colorddebff,
    Color? confirmButtonColor = ColorRes.color0065ff,
    Color? confirmTextColor = Colors.white,
    Color? cancelTextColor = ColorRes.color0065ff,
    String? cancelText = "取消",
    String? confirmText = "确定",
    double? buttonFontSize = 14,
  }) {
    if (descContainer == null) {
      descContainer = (c) {
        return Container(
          child: Text(
            desc,
            style: TextStyle(
              fontWeight: FontWeight.normal,
              color: descColor ?? ColorRes.color333333,
              fontSize: descFontSize ?? 16.sp,
            ),
          ),
        );
      };
    }
    return CommWidget.buildBottomSheetDialog(
      context,
      title: title ?? "温馨提示",
      buildView: (c) => Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            child: descContainer!(c),
          ),
          SizedBox(
            height: 40.w,
          ),
          Row(
            children: [
              Expanded(
                child: GestureDetector(
                  onTap: () {
                    print("当前选择事件 = ${cancelText}");
                    c.pop();
                  },
                  child: Container(
                    height: 40.w,
                    alignment: Alignment.center,
                    decoration: cancelBoxDecoration ??
                        BoxDecoration(
                          borderRadius: BorderRadius.circular(6.w),
                          border: Border.all(
                            color: ColorRes.color0065ff,
                            width: 1.w,
                          ),
                          color: cancelButtonColor ?? ColorRes.colorddebff,
                        ),
                    child: Text(
                      "${cancelText ?? "取消"}",
                      style: TextStyle(
                        fontSize: buttonFontSize ?? 14.sp,
                        color: cancelTextColor ?? ColorRes.color0065ff,
                      ),
                    ),
                  ),
                ),
              ),
              SizedBox(
                width: 15.w,
              ),
              Expanded(
                child: GestureDetector(
                  onTap: () {
                    print("当前选择事件 = ${confirmText}");
                    onConfirm?.call();
                    // c.pop();
                  },
                  child: Container(
                    height: 40.w,
                    alignment: Alignment.center,
                    decoration: confirmBoxDecoration ??
                        BoxDecoration(
                          borderRadius: BorderRadius.circular(6.w),
                          border: Border.all(
                            color: ColorRes.color0065ff,
                            width: 1.w,
                          ),
                          color: confirmButtonColor ?? ColorRes.color0065ff,
                        ),
                    child: Text(
                      "${confirmText ?? "确定"}",
                      style: TextStyle(fontSize: buttonFontSize ?? 14.sp, color: confirmTextColor ?? ColorRes.white),
                    ),
                  ),
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
